// pages/consult/consultant/consultant.js
let app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url:'',
    id:0,
    pageNum:1,
    pageSize:3,
    consultantId:0,
    consultant:'',
    content:'请问Python基础课程适合零基础学习吗？需要提前准备什么？',
    consultantTags:[],
    chargingStandard:[],
    question:'',
    anwser:'',
    consultantEvaluation:[],
    user:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      id:options.id,
      url:app.globalData.url
    })
    this.getConsultant()
    this.getConsultantTag()
    this.getChargingStandard()
    this.getQuestion()
    this.getAnwser()
    this.getConsultantEvaluation()
  },
  getConsultant(){
    wx.request({
      url: this.data.url+'consultant/'+this.data.id,
      method:'GET',
      success:resp=>{
        this.setData({
          consultant:resp.data.data
        })
      }
    })
  },
  getConsultantTag(){
    wx.request({
      url: this.data.url+'consultanttag/'+this.data.id,
      method:'GET',
      success:resp=>{
        this.setData({
          consultantTags:resp.data.data[0].tags
        })
        // console.log(this.data.consultantTags);
      }
    })
  },
  getChargingStandard(){
    wx.request({
      url: this.data.url+'ChargingStandardsController/consultantId/',
      method:'GET',
      data:{
        consultantId:this.data.id,
        pageNum:this.data.pageNum,
        pageSize:this.data.pageSize
      },
      success:resp=>{
        this.setData({
          chargingStandard:resp.data.data.list
        })
      }
    })
  },
  getQuestion(){
    wx.request({
      url: this.data.url+'Question/'+this.data.id,
      method:'GET',
      success:resp=>{
        this.setData({
          question:resp.data.data
        })
      }
    })
  },
  getAnwser(){
    wx.request({
      url: this.data.url+'Answer/'+this.data.id,
      method:'GET',
      success:resp=>{
        this.setData({
          anwser:resp.data.data
        })
      }
    })
  },
  getConsultantEvaluation(){
    wx.request({
      url: this.data.url+'ConsultantEvaluation/pageByConsultantId/',
      method:'GET',
      data:{
        pageNum:this.data.pageNum,
        pageSize:this.data.pageSize,
        consultantId:this.data.id
      },
      success:resp=>{
        this.setData({
          consultantEvaluation:resp.data.data.list
        })
      }
    })
  },
  addConsult(){
    wx.showModal({
      title: '确认咨询吗？',
      content: '期待你的咨询',
      complete: (res) => {
        if (res.cancel) {
          
        }
    
        if (res.confirm) {
          wx.request({
            url: this.data.url+'myconsult',
            method:'POST',
            data:{
              consultContent:this.data.content,
              consultTime:new Date,
              userId:this.data.user.id,
              consultantId:this.data.id,
              status:'未完成',
              assessStatus:'未评价'
            }
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let user=wx.getStorageSync('user')
    this.setData({
      user:user
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})